﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using Husb.Data;
using Husb.Util;
using CentralOffice.Task.Data;
using CentralOffice.Task.DataAccess;

using ApplicationTable = CentralOffice.Task.Data.ApplicationDataSet.ApplicationsDataTable;
using ApplicationRow = CentralOffice.Task.Data.ApplicationDataSet.ApplicationsRow;

using ApprovalTable = CentralOffice.Task.Data.ApprovalDataSet.ApprovalsDataTable;
using ApprovalRow = CentralOffice.Task.Data.ApprovalDataSet.ApprovalsRow;


namespace CentralOffice.Task.BusinessActions
{
    public class Applications : DataAccessManager<ApplicationDataSet, ApplicationTable, ApplicationRow, ApplicationAdapter>
    {
        public static bool Update(ApplicationDataSet applicationDataSet, ApprovalDataSet approvalDataSet)
        {
            return UpdateSelfAndDetail<ApprovalAdapter, ApprovalDataSet, ApprovalTable, ApprovalRow>(applicationDataSet, approvalDataSet, true, false, null);
        }

        public static bool IsExistApplicationCode(string applicationCode)
        {
            ApplicationAdapter adapter = new ApplicationAdapter();
            int cnt = adapter.CompareApplicationCode(applicationCode);
            if (cnt == 0) return false;

            return true;
        }

        public static string GetMaxApplicationCode(DateTime dateOfApplication)
        {
            ApplicationAdapter adapter = new ApplicationAdapter();
            string code = adapter.GetMaxApplicationCode(dateOfApplication);
            if (code.Length == 0) return DateTime.Now.ToString("yyyyMMdd") + "-001" ;

            code = code.Substring(9);

            return DateTime.Now.ToString("yyyyMMdd") + "-" + Husb.Util.CommonUtil.FillZero( (Int32.Parse(code) + 1), 3) ;
        }

        // 
        public static int DeleteBatch(string ids)
        {
            ApplicationAdapter adapter = new ApplicationAdapter();
            int cnt = adapter.DeleteBatch(ids);
            return cnt;
        }

        public static int RecoverBatch(string ids)
        {
            ApplicationAdapter adapter = new ApplicationAdapter();
            int cnt = adapter.RecoverBatch(ids);
            return cnt;
        }

        
    }
}
